package com.tingyuge.base.arithmetic.leetcode;

import java.util.*;

public class Test1 {
    public int[] twoSum(int[] nums, int target) {
        int result[] = new int[2];
      if(null == nums ||nums.length==0 ){
          return result;
      }
        Map<Integer, Integer> integerMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int temp = target - nums[i];

            if (integerMap.containsKey(temp)) {
                result[0] = i;
                result[1] = integerMap.get(temp);
            }
            integerMap.put(nums[i], i);
        }
        return result;
    }

    public static void main(String[] args) {
        Test1 test1 = new Test1();
        int[] nums = {3,2,3};
        int target = 6;
        Arrays.stream(test1.twoSum(nums, target)).forEach(System.out::println);
    }
}
